package com.jerei.store.controller;

import com.jerei.store.entity.Collect;
import com.jerei.store.service.ICollectService;
import com.jerei.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/collect")
public class CollectController extends BaseController{

    @Autowired
    private ICollectService collectService;

    @RequestMapping("/add")
    public JsonResult<Void> addCollect(Integer pid, HttpSession session){
        Integer uid=getUidFromSession(session);
        String username = getUsernameFromSession(session);
        collectService.addCollect(uid,pid,username);
        return new JsonResult<>(OK);


    }

    @RequestMapping("/show")
    public JsonResult<List<Collect>> show(Integer num,HttpSession session){
        Integer uid=getUidFromSession(session);
        List<Collect> list = collectService.showCollect(uid,num);
        return new JsonResult<>(OK,list);

    }

    @RequestMapping("/count")
    public JsonResult<Integer> count(HttpSession session){
        Integer uid=getUidFromSession(session);
        Integer num= collectService.count(uid);
        return new JsonResult<>(OK,num);
    }

    @RequestMapping("/del")
    public JsonResult<Void> delCollect(Integer pid,HttpSession session){
        Integer uid=getUidFromSession(session);
        collectService.delCollect(uid,pid);
        return new JsonResult<>(OK);

    }



}
